/**
 * 
 */

var event_source;

$(document).ready(function() {
	$("#cmd").keypress(input_handler);
	$("input#cmd").focus();
});

function input_handler(e) {
	if (e.keyCode == 13) {
		$("#out").append($("<p>" + this.value + "</p>"));
		this.value = "";

		if (!!window.EventSource) {
			var source = new EventSource('http://localhost:8765');
			alert("supported!");
		} else {
			alert("sse not support!");// Result to xhr polling :(
		}
	}
}

function handle_name() {
	event_source = new EventSource('sse');
	source.addEventListener('message', function(e) {
		console.log(e.data);
	}, false);

	source.addEventListener('open', function(e) {
		// Connection was opened.
	}, false);

	source.addEventListener('error', function(e) {
		if (e.eventPhase == EventSource.CLOSED) {
			// Connection was closed.
		}
	}, false);
}

function handle_password() {
}

function open_eventsource() {
}
